<?php

namespace Fn;

class Country {

    static function getCountry($p = 'ALL', $field = 'ALL') {
        $country = array(
            'AF' => 'AF:Afghanistan:阿富汗',
            'AX' => 'AX:Aland Islands:奥兰群岛',
            'AL' => 'AL:Albania:阿尔巴尼亚',
            'DZ' => 'DZ:Algeria:阿尔及利亚',
            'AS' => 'AS:American Samoa:美属萨摩亚',
            'AD' => 'AD:Andorra:安道尔',
            'AO' => 'AO:Angola:安哥拉',
            'AI' => 'AI:Anguilla:安圭拉',
            'AG' => 'AG:Antigua and Barbuda:安提瓜和巴布达',
            'AR' => 'AR:Argentina:阿根廷',
            'AM' => 'AM:Armenia:亚美尼亚',
        	'AN' => 'AN:Netherlands Antilles:荷属安的列斯群岛',
            'AW' => 'AW:Aruba:阿鲁巴',
            'AU' => 'AU:Australia:澳大利亚',
            'AT' => 'AT:Austria:奥地利',
            'AZ' => 'AZ:Azerbaijan:阿塞拜疆',
            'BD' => 'BD:Bangladesh:孟加拉',
            'BH' => 'BH:Bahrain:巴林',
            'BS' => 'BS:Bahamas:巴哈马',
            'BB' => 'BB:Barbados:巴巴多斯',
            'BY' => 'BY:Belarus:白俄罗斯',
            'BE' => 'BE:Belgium:比利时',
            'BZ' => 'BZ:Belize:伯利兹',
            'BJ' => 'BJ:Benin:贝宁',
            'BM' => 'BM:Bermuda:百慕大',
            'BT' => 'BT:Bhutan:不丹',
            'BO' => 'BO:Bolivia:玻利维亚',
            'BA' => 'BA:Bosnia and Herzegovina:波斯尼亚和黑塞哥维那',
            'BW' => 'BW:Botswana:博茨瓦纳',
            'BV' => 'BV:Bouvet Island:布维岛',
            'BR' => 'BR:Brazil:巴西',
            'BN' => 'BN:Brunei:文莱',
            'BG' => 'BG:Bulgaria:保加利亚',
            'BF' => 'BF:Burkina Faso:布基纳法索',
            'BI' => 'BI:Burundi:布隆迪',
            'KH' => 'KH:Cambodia:柬埔寨',
            'CM' => 'CM:Cameroon:喀麦隆',
            'CA' => 'CA:Canada:加拿大',
            'CV' => 'CV:Cape Verde:佛得角',
            'CF' => 'CF:Central African Republic:中非',
            'TD' => 'TD:Chad:乍得',
            'CW' => 'CW:Curacao:库拉索',
            'CL' => 'CL:Chile:智利',
            'CX' => 'CX:Christmas Islands:圣诞岛',
            'CC' => 'CC:Cocos (keeling) Islands:科科斯（基林）群岛',
            'CO' => 'CO:Colombia:哥伦比亚',
            'KM' => 'KM:Comoros:科摩罗',
        	'KY'	=> 'KY:Cayman Islands:开曼群岛',
            'CD' => 'CD:Congo (Congo-Kinshasa):刚果（金）',
            'CG' => 'CG:Congo:刚果',
            'CK' => 'CK:Cook Islands:库克群岛',
            'CR' => 'CR:Costa Rica:哥斯达黎加',
            'CI' => 'CI:Cote D\'Ivoire:科特迪瓦',
            'CN' => 'CN:China:中国',
            'HR' => 'HR:Croatia:克罗地亚',
            'CU' => 'CU:Cuba:古巴',
            'CZ' => 'CZ:Czech:捷克',
            'CY' => 'CY:Cyprus:塞浦路斯',
            'DK' => 'DK:Denmark:丹麦',
            'DJ' => 'DJ:Djibouti:吉布提',
            'DM' => 'DM:Dominica:多米尼克',
        	'DO' => 'DO:Dominican Republic:多米尼加',
            //'-'=>':East Timor:东帝汶',
            'EC' => 'EC:Ecuador:厄瓜多尔',
            'EG' => 'EG:Egypt:埃及',
            'GQ' => 'GQ:Equatorial Guinea:赤道几内亚',
            'ER' => 'ER:Eritrea:厄立特里亚',
            'EE' => 'EE:Estonia:爱沙尼亚',
            'ET' => 'ET:Ethiopia:埃塞俄比亚',
            'FO' => 'FO:Faroe Islands:法罗群岛',
            'FJ' => 'FJ:Fiji:斐济',
            'FI' => 'FI:Finland:芬兰',
            'FR' => 'FR:France:法国',
            'FX' => 'FX:Franch Metropolitan:法国大都会',
            'GF' => 'GF:Franch Guiana:法属圭亚那',
            'PF' => 'PF:French Polynesia:法属波利尼西亚',
			'PM' => 'PM:Franch PierreandMiquelon:圣皮埃尔与密克隆',
            'GA' => 'GA:Gabon:加蓬',
            'GM' => 'GM:Gambia:冈比亚',
            'GE' => 'GE:Georgia:格鲁吉亚',
            'DE' => 'DE:Germany:德国',
            'GH' => 'GH:Ghana:加纳',
            'GI' => 'GI:Gibraltar:直布罗陀',
            'GR' => 'GR:Greece:希腊',
            'GD' => 'GD:Grenada:格林纳达',
            'GP' => 'GP:Guadeloupe:瓜德罗普岛',
            'GU' => 'GU:Guam:关岛',
            'GT' => 'GT:Guatemala:危地马拉',
            'GG' => 'GG:Guernsey:根西岛',
            'GW' => 'GW:Guinea-Bissau:几内亚比绍',
            'GN' => 'GN:Guinea:几内亚',
            'GY' => 'GY:Guyana:圭亚那',
            'HK' => 'HK:Hong Kong:香港 （中国）',
            'HT' => 'HT:Haiti:海地',
            'HN' => 'HN:Honduras:洪都拉斯',
            'HU' => 'HU:Hungary:匈牙利',
            'IS' => 'IS:Iceland:冰岛',
            'IN' => 'IN:India:印度',
        	'IO' => 'IO:British Indian Ocean Territory:英属印度洋领地',
            'ID' => 'ID:Indonesia:印度尼西亚',
            'IR' => 'IR:Iran:伊朗',
            'IQ' => 'IQ:Iraq:伊拉克',
            'IE' => 'IE:Ireland:爱尔兰',
            'IM' => 'IM:Isle of Man:马恩岛',
            'IL' => 'IL:Israel:以色列',
            'IT' => 'IT:Italy:意大利',
            'JM' => 'JM:Jamaica:牙买加',
            'JP' => 'JP:Japan:日本',
            'JE' => 'JE:Jersey Island:泽西岛',
            'JO' => 'JO:Jordan:约旦',
            'KZ' => 'KZ:Kazakstan:哈萨克斯坦',
            'KE' => 'KE:Kenya:肯尼亚',
            'KI' => 'KI:Kiribati:基里巴斯',
            'KR' => 'KR:Republic of Korea:韩国',
            'KD' => 'KD:Korea (North):朝鲜',
            'KW' => 'KW:Kuwait:科威特',
            'KG' => 'KG:Kyrgyzstan:吉尔吉斯斯坦',
            'LO' => 'LO:Laos:老挝',
            'LV' => 'LV:Latvia:拉脱维亚',
            'LB' => 'LB:Lebanon:黎巴嫩',
            'LS' => 'LS:Lesotho:莱索托',
            'LR' => 'LR:Liberia:利比里亚',
            'LY' => 'LY:Libya:利比亚',
            'LI' => 'LI:Liechtenstein:列支敦士登',
            'LT' => 'LT:Lithuania:立陶宛',
            'LU' => 'LU:Luxembourg:卢森堡',
            'MO' => 'MO:Macau:澳门（中国）',
            'MK' => 'MK:Macedonia:马其顿',
            'MW' => 'MW:Malawi:马拉维',
            'MY' => 'MY:Malaysia:马来西亚',
            'MG' => 'MG:Madagascar:马达加斯加',
            'MV' => 'MV:Maldives:马尔代夫',
            'ML' => 'ML:Mali:马里',
            'MT' => 'MT:Malta:马耳他',
            'MH' => 'MH:Marshall Islands:马绍尔群岛',
            'MQ' => 'MQ:Martinique:马提尼克岛',
            'MR' => 'MR:Mauritania:毛里塔尼亚',
            'MU' => 'MU:Mauritius:毛里求斯',
            'YT' => 'YT:Mayotte:马约特',
            'MX' => 'MX:Mexico:墨西哥',
            'MF' => 'MF:Micronesia:密克罗尼西亚',
            'MD' => 'MD:Moldova:摩尔多瓦',
            'MC' => 'MC:Monaco:摩纳哥',
            'MN' => 'MN:Mongolia:蒙古',
            'ME' => 'ME:Montenegro:黑山',
            'MS' => 'MS:Montserrat:蒙特塞拉特',
            'MA' => 'MA:Morocco:摩洛哥',
            'MZ' => 'MZ:Mozambique:莫桑比克',
            'MM' => 'MM:Myanmar:缅甸',
            'NA' => 'NA:Namibia:纳米比亚',
            'NR' => 'NR:Nauru:瑙鲁',
            'NP' => 'NP:Nepal:尼泊尔',
            'NL' => 'NL:Netherlands:荷兰',
            'NC' => 'NC:New Caledonia:新喀里多尼亚',
            'NZ' => 'NZ:New Zealand:新西兰',
            'NI' => 'NI:Nicaragua:尼加拉瓜',
            'NE' => 'NE:Niger:尼日尔',
            'NG' => 'NG:Nigeria:尼日利亚',
            'NU' => 'NU:Niue:纽埃',
            'NF' => 'NF:Norfolk Island:诺福克岛',
            'NO' => 'NO:Norway:挪威',
            'OM' => 'OM:Oman:阿曼',
            'PK' => 'PK:Pakistan:巴基斯坦',
            'PW' => 'PW:Palau:帕劳',
            'PS' => 'PS:Palestine:巴勒斯坦',
            'PA' => 'PA:Panama:巴拿马',
            'PG' => 'PG:Papua New Guinea:巴布亚新几内亚',
            'PY' => 'PY:Paraguay:巴拉圭',
            'PE' => 'PE:Peru:秘鲁',
            'PH' => 'PH:Philippines:菲律宾',
            'PN' => 'PN:Pitcairn Islands:皮特凯恩群岛',
            'PL' => 'PL:Poland:波兰',
            'PT' => 'PT:Portugal:葡萄牙',
            'PR' => 'PR:Puerto Rico:波多黎各',
            'QA' => 'QA:Qatar:卡塔尔',
            'RE' => 'RE:Reunion:留尼汪岛',
            'RO' => 'RO:Romania:罗马尼亚',
            'RW' => 'RW:Rwanda:卢旺达',
            'RU' => 'RU:Russian Federation:俄罗斯联邦',
            'SH' => 'SH:Saint Helena:圣赫勒拿',
            'KN' => 'KN:Saint Kitts-Nevis:圣基茨和尼维斯',
            'LC' => 'LC:Saint Lucia:圣卢西亚',
            'VG' => 'VG:Saint Vincent and the Grenadines:圣文森特和格林纳丁斯',
            'SV' => 'SV:El Salvador:萨尔瓦多',
            'WS' => 'WS:Samoa:萨摩亚',
            'SM' => 'SM:San Marino:圣马力诺',
            'ST' => 'ST:Sao Tome and Principe:圣多美和普林西比',
            'SA' => 'SA:Saudi Arabia:沙特阿拉伯',
            'SN' => 'SN:Senegal:塞内加尔',
            'SC' => 'SC:Seychelles:塞舌尔',
            'SL' => 'SL:Sierra Leone:塞拉利昂',
            'SG' => 'SG:Singapore:新加坡',
            'RS' => 'RS:Serbia:塞尔维亚',
            'SK' => 'SK:Slovakia:斯洛伐克',
            'SI' => 'SI:Slovenia:斯洛文尼亚',
            'SB' => 'SB:Solomon Islands:所罗门群岛',
            'SO' => 'SO:Somalia:索马里',
            'ZA' => 'ZA:South Africa:南非',
            'ES' => 'ES:Spain:西班牙',
            'LK' => 'LK:Sri Lanka:斯里兰卡',
            'SD' => 'SD:Sudan:苏丹',
            'SR' => 'SR:Suriname:苏里南',
            'SZ' => 'SZ:Swaziland:斯威士兰',
            'SE' => 'SE:Sweden:瑞典',
            'CH' => 'CH:Switzerland:瑞士',
            'SY' => 'SY:Syria:叙利亚',
            'TJ' => 'TJ:Tajikistan:塔吉克斯坦',
            'TZ' =>	'TZ:Tanzania:坦桑尼亚',
            'TW' => 'TW:Taiwan:台湾 （中国）',
            'TH' => 'TH:Thailand:泰国',
            'TT' => 'TT:Trinidad and Tobago:特立尼达和多巴哥',
            'TL' => 'TL:Timor-Leste:东帝汶',
            'TG' => 'TG:Togo:多哥',
            'TK' => 'TK:Tokelau:托克劳',
            'TO' => 'TO:Tonga:汤加',
            'TN' => 'TN:Tunisia:突尼斯',
            'TR' => 'TR:Turkey:土耳其',
            'TM' => 'TM:Turkmenistan:土库曼斯坦',
            'TV' => 'TV:Tuvalu:图瓦卢',
            'UG' => 'UG:Uganda:乌干达',
            'UA' => 'UA:Ukraine:乌克兰',
            'AE' => 'AE:United Arab Emirates:阿拉伯联合酋长国',
            'UK' => 'UK:United Kingdom:英国',
            //'GB'=>'GB:United Kingdom:英国[大不列颠]',
            'US' => 'US:United States:美国',
            'UY' => 'UY:Uruguay:乌拉圭',
            'UZ' => 'UZ:Uzbekistan:乌兹别克斯坦',
            'VU' => 'VU:Vanuatu:瓦努阿图',
            'VA' => 'VA:Vatican City:梵蒂冈',
            'VE' => 'VE:Venezuela:委内瑞拉',
            'VN' => 'VN:Vietnam:越南',
            'WF' => 'WF:Wallis and Futuna:瓦利斯群岛和富图纳群岛',
            'EH' => 'EH:Western Sahara:西撒哈拉',
            'YE' => 'YE:Yemen:也门',
            //'-'=>':Yugoslavia:南斯拉夫',
            'ZM' => 'ZM:Zambia:赞比亚',
            'ZW' => 'ZW:Zimbabwe:津巴布韦',
        	'GL'	=> 'GL:Greenland:格陵兰',
        	'VI'	=> 'VI:Virgin Islands (U.S.):维尔京群岛(美国)'
        );
        $p = trim(strtoupper($p));
        $field = trim(strtoupper($field));

        if ($p === 'ALL') {
            foreach ($country as $k => $v) {
                list($iso, $en, $cn) = explode(':', $v);
                $country[$k] = array('ISO' => $iso, 'EN' => $en, 'CN' => $cn);
            }
            if ($field !== 'ALL') {
                foreach ($country as $k => $v) {
                    $country[$k] = $v[$field];
                }
            }
            return $country;
        }
        if (isset($country[$p])) {
            $p = $p === 'GB' ? 'UK' : $p;
            $c = explode(':', $country[$p]);
            $r = array('ISO' => $c[0], 'EN' => $c[1], 'CN' => $c[2]);
            return ($field === 'ALL') ? $r : $r[$field];
        }
        return "未知";
    }

    static function iso3To2($code, $code2to3 = false) {
        $code = ($code === 'UK') ? 'GB' : $code;
        $r = array('CUR'=>'CW', 'ALA' => 'AX', 'AFG' => 'AF', 'ALB' => 'AL', 'DZA' => 'DZ', 'ASM' => 'AS', 'AND' => 'AD', 'AGO' => 'AO', 'AIA' => 'AI', 'ATA' => 'AQ', 'ATG' => 'AG', 'ARG' => 'AR', 'ARM' => 'AM', 'ABW' => 'AW', 'AUS' => 'AU', 'AUT' => 'AT', 'AZE' => 'AZ', 'BHS' => 'BS', 'BHR' => 'BH', 'BGD' => 'BD', 'BRB' => 'BB', 'BLR' => 'BY', 'BEL' => 'BE', 'BLZ' => 'BZ', 'BEN' => 'BJ', 'BMU' => 'BM', 'BTN' => 'BT', 'BOL' => 'BO', 'BIH' => 'BA', 'BWA' => 'BW', 'BVT' => 'BV', 'BRA' => 'BR', 'IOT' => 'IO', 'BRN' => 'BN', 'BGR' => 'BG', 'BFA' => 'BF', 'BDI' => 'BI', 'KHM' => 'KH', 'CMR' => 'CM', 'CAN' => 'CA', 'CPV' => 'CV', 'CYM' => 'KY', 'CAF' => 'CF', 'TCD' => 'TD', 'CHL' => 'CL', 'CHN' => 'CN', 'CXR' => 'CX', 'CCK' => 'CC', 'COL' => 'CO', 'COM' => 'KM', 'COG' => 'CG', 'COK' => 'CK', 'CRI' => 'CR', 'CIV' => 'CI', 'HRV' => 'HR', 'CUB' => 'CU', 'CYP' => 'CY', 'CZE' => 'CZ', 'DNK' => 'DK', 'DJI' => 'DJ', 'DMA' => 'DM', 'DOM' => 'DO', 'TMP' => 'TP', 'ECU' => 'EC', 'EGY' => 'EG', 'SLV' => 'SV', 'GNQ' => 'GQ', 'ERI' => 'ER', 'EST' => 'EE', 'ETH' => 'ET', 'FLK' => 'FK', 'FRO' => 'FO', 'FJI' => 'FJ', 'FIN' => 'FI', 'FRA' => 'FR', 'FXX' => 'FX', 'GUF' => 'GF', 'PYF' => 'PF', 'ATF' => 'TF', 'GAB' => 'GA', 'GMB' => 'GM', 'GEO' => 'GE', 'DEU' => 'DE', 'GHA' => 'GH', 'GIB' => 'GI', 'GRC' => 'GR', 'GRL' => 'GL', 'GRD' => 'GD', 'GLP' => 'GP', 'GUM' => 'GU', 'GTM' => 'GT', 'GIN' => 'GN', 'GNB' => 'GW', 'GUY' => 'GY', 'HTI' => 'HT', 'HMD' => 'HM', 'HND' => 'HN', 'HKG' => 'HK', 'HUN' => 'HU', 'ISL' => 'IS', 'IND' => 'IN', 'IDN' => 'ID', 'IRN' => 'IR', 'IRQ' => 'IQ', 'IRL' => 'IE', 'ISR' => 'IL', 'ITA' => 'IT', 'JAM' => 'JM', 'JPN' => 'JP', 'JOR' => 'JO', 'KAZ' => 'KZ', 'KEN' => 'KE', 'KIR' => 'KI', 'PRK' => 'KP', 'KOR' => 'KR', 'KWT' => 'KW', 'KGZ' => 'KG', 'LAO' => 'LA', 'LVA' => 'LV', 'LBN' => 'LB', 'LSO' => 'LS', 'LBR' => 'LR', 'LBY' => 'LY', 'LIE' => 'LI', 'LTU' => 'LT', 'LUX' => 'LU', 'MAC' => 'MO', 'MKD' => 'MK', 'MDG' => 'MG', 'MWI' => 'MW', 'MYS' => 'MY', 'MDV' => 'MV', 'MLI' => 'ML', 'MLT' => 'MT', 'MHL' => 'MH', 'MTQ' => 'MQ', 'MRT' => 'MR', 'MUS' => 'MU', 'MYT' => 'YT', 'MEX' => 'MX', 'FSM' => 'FM', 'MDA' => 'MD', 'MCO' => 'MC', 'MNG' => 'MN', 'MSR' => 'MS', 'MAR' => 'MA', 'MOZ' => 'MZ', 'MMR' => 'MM', 'NAM' => 'NA', 'NRU' => 'NR', 'NPL' => 'NP', 'NLD' => 'NL', 'ANT' => 'AN', 'NCL' => 'NC', 'NZL' => 'NZ', 'NIC' => 'NI', 'NER' => 'NE', 'NGA' => 'NG', 'NIU' => 'NU', 'NFK' => 'NF', 'MNP' => 'MP', 'NOR' => 'NO', 'OMN' => 'OM', 'PAK' => 'PK', 'PLW' => 'PW', 'PAN' => 'PA', 'PNG' => 'PG', 'PRY' => 'PY', 'PER' => 'PE', 'PHL' => 'PH', 'PCN' => 'PN', 'POL' => 'PL', 'PRT' => 'PT', 'PRI' => 'PR', 'QAT' => 'QA', 'REU' => 'RE', 'ROM' => 'RO', 'RUS' => 'RU', 'RWA' => 'RW', 'KNA' => 'KN', 'LCA' => 'LC', 'VCT' => 'VC', 'WSM' => 'WS', 'SMR' => 'SM', 'STP' => 'ST', 'SAU' => 'SA', 'SEN' => 'SN', 'SYC' => 'SC', 'SLE' => 'SL', 'SGP' => 'SG', 'SVK' => 'SK', 'SVN' => 'SI', 'SLB' => 'SB', 'SOM' => 'SO', 'ZAF' => 'ZA', 'SGS' => 'GS', 'ESP' => 'ES', 'LKA' => 'LK', 'SHN' => 'SH', 'SPM' => 'PM', 'SDN' => 'SD', 'SUR' => 'SR', 'SJM' => 'SJ', 'SWZ' => 'SZ', 'SWE' => 'SE', 'CHE' => 'CH', 'SYR' => 'SY', 'TWN' => 'TW', 'TJK' => 'TJ', 'TZA' => 'TZ', 'THA' => 'TH', 'TGO' => 'TG', 'TKL' => 'TK', 'TON' => 'TO', 'TTO' => 'TT', 'TUN' => 'TN', 'TUR' => 'TR', 'TKM' => 'TM', 'TCA' => 'TC', 'TUV' => 'TV', 'UGA' => 'UG', 'UKR' => 'UA', 'ARE' => 'AE', 'GBR' => 'GB', 'USA' => 'US', 'UMI' => 'UM', 'URY' => 'UY', 'UZB' => 'UZ', 'VUT' => 'VU', 'VAT' => 'VA', 'VEN' => 'VE', 'VNM' => 'VN', 'VGB' => 'VG', 'VIR' => 'VI', 'WLF' => 'WF', 'ESH' => 'EH', 'YEM' => 'YE', 'YUG' => 'YU', 'ZAR' => 'ZR', 'ZMB' => 'ZM', 'ZWE' => 'ZW', 'IMN' => 'IM', 'XXX' => 'XX', 'SRB' => 'RS');
        if ($code2to3) {
            $r = array_flip($r);
            return (isset($r[$code])) ? $r[$code] : 'XXX';
        } else {
            return (isset($r[$code])) ? $r[$code] : 'XX';
        }
    }

    static function iso2To3($code) {
        return self::iso3To2($code, true);
    }

    static function enName($iso = 'ALL') {
        $iso = ($iso != 'ALL' && strlen($iso) === 3) ? self::iso3To2($iso) : $iso;
        if ($iso == 'GB') {
            $iso = "UK";
        }
        return self::getCountry($iso, 'EN');
    }

    static function cnName($iso = 'ALL') {
        $iso = ($iso != 'ALL' && strlen($iso) === 3) ? self::iso3To2($iso) : $iso;
        return self::getCountry($iso, 'CN');
    }

    static function getIsoByEnName($enName,$error=false) {
    	
    	/*-----国家名与系统中国家En名格式化-Strat------*/
    	
        if(trim($enName)===trim("South Korea")||trim($enName)===trim("Korea (South)")||trim($enName)===trim("Korea Republic of")){
            $enName="Republic of Korea";  //韩国
        }
        if(trim($enName)===trim("Czech Republic")){ 
        	$enName="Czech";    //捷克
        }
        if(trim($enName)===trim("Slovakia (Slovak Republic)")){
        	$enName="Slovakia";    //斯洛伐克
        }
        if(trim($enName)===trim("Kazakhstan")){
        	$enName="Kazakstan";    //哈萨克斯坦
        }
        if(trim($enName)===trim("Russion Federation")){
            $enName = "Russian Federation";
        }
        /*-----国家名与系统中国家En名格式化-END------*/
        
        $countryArr = self::getCountry("ALL", 'EN');
        //'RO'=>'RO:Romania:罗马尼亚',
        $enName = trim($enName);  //过滤空白
        list($enName, $enName2, $enName3) = self::aaaa($enName);
        $res = array();
        foreach ($countryArr as $key => $v) {
            list($v,$v2,$v3) =self::aaaa($v);
            if ($enName === $v) {
                $res[0] = $key;
              
            } else  if ($enName2 === $v2) {
                $res[1] = $key;
            }/* else if ($enName3 === $v3) {
                $res[2] = $key;
            }*/
        }
        if(isset($res[0]) && !empty($res[0])){
            return $res[0];
        }else if(isset($res[1]) && !empty($res[1])){
            return $res[1];
        }/*else if(isset($res[2]) && !empty($res[2])){
            return $res[2]
        }*/
        return $error;
        
    }

    static function getIsoByCnName($cnName,$error=false) {
        /*-----国家名与系统中国家En名格式化-END------*/
        
        $countryArr = self::getCountry("ALL", 'CN');
        $cnName = trim($cnName);  //过滤空白
        $res = array();
        foreach ($countryArr as $key => $v) {
            if ($cnName === $v) {
                $res[0] = $key;
            } 
        } 
        if(isset($res[0]) && !empty($res[0])){
            return $res[0];
        }
        return $error;
    }


    static function aaaa($str) {
        $str = trim($str);
        $str = preg_replace('/\s+/', ' ', $str);
        $str2 = preg_replace('/\W+/', '-', $str);
        $str3 = preg_replace('/\W+/', '', $str);
        return array($str, $str2, $str3);
    }
	
	//各个国家的电话区号
	static function getCountryCode($p = 'ALL', $field = 'ALL'){
		$country = array(
			'AF' => 'AF:0093:阿富汗',
			//'AX' => 'AX:Aland Islands:奥兰群岛',
            'AL' => 'AL:00355:阿尔巴尼亚',
            'DZ' => 'DZ:00213:阿尔及利亚',
            'AS' => 'AS:00684:美属萨摩亚',
            'AD' => 'AD:00376:安道尔',
            'AO' => 'AO:00244:安哥拉',
            'AI' => 'AI:001264:安圭拉',
            'AG' => 'AG:001268:安提瓜和巴布达',
            'AR' => 'AR:0054:阿根廷',
            'AM' => 'AM:00374:亚美尼亚',
        	'AN' => 'AN:00599:荷属安的列斯群岛',
            'AW' => 'AW:00297:阿鲁巴',
            'AU' => 'AU:0061:澳大利亚',
            'AT' => 'AT:0043:奥地利',
            'AZ' => 'AZ:00994:阿塞拜疆',
            'BD' => 'BD:00880:孟加拉',
            'BH' => 'BH:00973:巴林',
            'BS' => 'BS:001242:巴哈马',
            'BB' => 'BB:001246:巴巴多斯',
            'BY' => 'BY:00375:白俄罗斯',
            'BE' => 'BE:0032:比利时',
            'BZ' => 'BZ:00501:伯利兹',
            'BJ' => 'BJ:00229:贝宁',
            'BM' => 'BM:001441:百慕大',
            'BT' => 'BT:00975:不丹',
            'BO' => 'BO:00591:玻利维亚',
            'BA' => 'BA:00387:波斯尼亚和黑塞哥维那',
            'BW' => 'BW:00267:博茨瓦纳',
            //'BV' => 'BV:Bouvet Island:布维岛',
            'BR' => 'BR:0055:巴西',
            'BN' => 'BN:00673:文莱',
            'BG' => 'BG:00359:保加利亚',
            'BF' => 'BF:00226:布基纳法索',
            'BI' => 'BI:00257:布隆迪',
            'KH' => 'KH:00855:柬埔寨',
            'CM' => 'CM:00237:喀麦隆',
            'CA' => 'CA:001:加拿大',
            'CV' => 'CV:00238:佛得角',
            'CF' => 'CF:00236:中非',
            'TD' => 'TD:00235:乍得',
            'CL' => 'CL:0056:智利',
            'CX' => 'CX:00619164:圣诞岛',
            'CC' => 'CC:00619162:科科斯（基林）群岛',
            'CO' => 'CO:0057:哥伦比亚',
            'KM' => 'KM:00269:科摩罗',
        	'KY'	=> 'KY:001345:开曼群岛',
            'CD' => 'CD:00243:刚果（金）',
            'CG' => 'CG:00242 :刚果',
            'CK' => 'CK:00682:库克群岛',
            'CR' => 'CR:00506:哥斯达黎加',
            'CI' => 'CI:00225:科特迪瓦',
            'CN' => 'CN:0086:中国',
            'HR' => 'HR:00385:克罗地亚',
            'CU' => 'CU:0053:古巴',
            'CZ' => 'CZ:00420:捷克',
            'CY' => 'CY:00357:塞浦路斯',
            'DK' => 'DK:0045:丹麦',
            'DJ' => 'DJ:00253:吉布提',
            'DM' => 'DM:001767:多米尼克',
        	'DO' => 'DO:001809:多米尼加',
            'EC' => 'EC:00593:厄瓜多尔',
            'EG' => 'EG:0020:埃及',
            'GQ' => 'GQ:00240:赤道几内亚',
            'ER' => 'ER:00291:厄立特里亚',
            'EE' => 'EE:00372:爱沙尼亚',
            'ET' => 'ET:00251:埃塞俄比亚',
            'FO' => 'FO:00298:法罗群岛',
            'FJ' => 'FJ:00679:斐济',
            'FI' => 'FI:00358:芬兰',
            'FR' => 'FR:0033:法国',
            //'FX' => 'FX:Franch Metropolitan:法国大都会',
            'GF' => 'GF:00594:法属圭亚那',
            'PF' => 'PF:00689:法属波利尼西亚',
            'GA' => 'GA:00241:加蓬',
            'GM' => 'GM:00220:冈比亚',
            'GE' => 'GE:00995:格鲁吉亚',
            'DE' => 'DE:0049:德国',
            'GH' => 'GH:00233:加纳',
            'GI' => 'GI:00350:直布罗陀',
            'GR' => 'GR:0030:希腊',
            'GD' => 'GD:001473:格林纳达',
            //'GP' => 'GP:Guadeloupe:瓜德罗普岛',
            'GU' => 'GU:001671:关岛',
            'GT' => 'GT:00502:危地马拉',
            'GG' => 'GG:0044:根西岛',
            'GW' => 'GW:00245:几内亚比绍',
            'GN' => 'GN:00224:几内亚',
            'GY' => 'GY:00592:圭亚那',
            'HK' => 'HK:00852:香港 （中国）',
            'HT' => 'HT:00509:海地',
            'HN' => 'HN:00504:洪都拉斯',
            'HU' => 'HU:0036:匈牙利',
            'IS' => 'IS:00354:冰岛',
            'IN' => 'IN:0091:印度',
        	'IO' => 'IO:00246:英属印度洋领地',
            'ID' => 'ID:0062:印度尼西亚',
            'IR' => 'IR:0098:伊朗',
            'IQ' => 'IQ:00964:伊拉克',
            'IE' => 'IE:00353:爱尔兰',
            'IM' => 'IM:0044:马恩岛',
            'IL' => 'IL:00972:以色列',
            'IT' => 'IT:0039:意大利',
            'JM' => 'JM:001876:牙买加',
            'JP' => 'JP:0081:日本',
            'JO' => 'JO:00962:约旦',
            'KZ' => 'KZ:007:哈萨克斯坦',
            'KE' => 'KE:00254:肯尼亚',
            'KI' => 'KI:00686:基里巴斯',
            'KR' => 'KR:0082:韩国',
            'KD' => 'KD:00850:朝鲜',
            'KW' => 'KW:00965:科威特',
            'KG' => 'KG:00331:吉尔吉斯斯坦',
            'LO' => 'LO:00856:老挝',
            'LV' => 'LV:00371:拉脱维亚',
            'LB' => 'LB:00961:黎巴嫩',
            'LS' => 'LS:00266:莱索托',
            'LR' => 'LR:00231:利比里亚',
            'LY' => 'LY:00218:利比亚',
            'LI' => 'LI:00423:列支敦士登',
            'LT' => 'LT:00370:立陶宛',
            'LU' => 'LU:00352:卢森堡',
            'MO' => 'MO:00853:澳门（中国）',
            'MK' => 'MK:00389:马其顿',
            'MW' => 'MW:00265:马拉维',
            'MY' => 'MY:0060:马来西亚',
            'MG' => 'MG:00261:马达加斯加',
            'MV' => 'MV:00960:马尔代夫',
            'ML' => 'ML:00223:马里',
            'MT' => 'MT:00356:马耳他',
            'MH' => 'MH:00692:马绍尔群岛',
            'MQ' => 'MQ:00596:马提尼克岛',
            'MR' => 'MR:00222:毛里塔尼亚',
            'MU' => 'MU:00230:毛里求斯',
            'YT' => 'YT:00269:马约特',
            'MX' => 'MX:0052:墨西哥',
            'MF' => 'MF:00691:密克罗尼西亚',
            'MD' => 'MD:00373:摩尔多瓦',
            'MC' => 'MC:00377:摩纳哥',
            'MN' => 'MN:00976:蒙古',
            'ME' => 'ME:00382:黑山',
            'MS' => 'MS:001664:蒙特塞拉特',
            'MA' => 'MA:00212:摩洛哥',
            'MZ' => 'MZ:00258:莫桑比克',
            'MM' => 'MM:0095:缅甸',
            'NA' => 'NA:00264:纳米比亚',
            'NR' => 'NR:00674:瑙鲁',
            'NP' => 'NP:00977:尼泊尔',
            'NL' => 'NL:0031:荷兰',
            'NC' => 'NC:00687:新喀里多尼亚',
            'NZ' => 'NZ:0064:新西兰',
            'NI' => 'NI:00505:尼加拉瓜',
            'NE' => 'NE:00227:尼日尔',
            'NG' => 'NG:00234:尼日利亚',
            'NU' => 'NU:00683:纽埃',
            'NF' => 'NF:00672:诺福克岛',
            'NO' => 'NO:0047:挪威',
            'OM' => 'OM:00968:阿曼',
            'PK' => 'PK:0092:巴基斯坦',
            'PW' => 'PW:00680:帕劳',
            'PS' => 'PS:00970:巴勒斯坦',
            'PA' => 'PA:00507:巴拿马',
            'PG' => 'PG:00675:巴布亚新几内亚',
            'PY' => 'PY:00595:巴拉圭',
            'PE' => 'PE:0051:秘鲁',
            'PH' => 'PH:0063:菲律宾',
            //'PN' => 'PN:Pitcairn Islands:皮特凯恩群岛',
            'PL' => 'PL:0048:波兰',
            'PT' => 'PT:00351:葡萄牙',
            'PR' => 'PR:001809:波多黎各',
            'QA' => 'QA:00974:卡塔尔',
            'RE' => 'RE:00262:留尼汪岛',
            'RO' => 'RO:0040:罗马尼亚',
            'RW' => 'RW:00250:卢旺达',
            'RU' => 'RU:007:俄罗斯联邦',
            'SH' => 'SH:00290:圣赫勒拿',
            'KN' => 'KN:001869:圣基茨和尼维斯',
            'LC' => 'LC:001758:圣卢西亚',
            'VG' => 'VG:00784:圣文森特和格林纳丁斯',
            'SV' => 'SV:00503:萨尔瓦多',
            'WS' => 'WS:00685:萨摩亚',
            'SM' => 'SM:00378:圣马力诺',
            'ST' => 'ST:00239:圣多美和普林西比',
            'SA' => 'SA:00966:沙特阿拉伯',
            'SN' => 'SN:00221:塞内加尔',
            'SC' => 'SC:00248:塞舌尔',
            'SL' => 'SL:00232:塞拉利昂',
            'SG' => 'SG:0065:新加坡',
            'RS' => 'RS:00381:塞尔维亚',
            'SK' => 'SK:00421:斯洛伐克',
            'SI' => 'SI:00386:斯洛文尼亚',
            'SB' => 'SB:00677:所罗门群岛',
            'SO' => 'SO:00252:索马里',
            'ZA' => 'ZA:0027:南非',
            'ES' => 'ES:0034:西班牙',
            'LK' => 'LK:0094:斯里兰卡',
            'SD' => 'SD:00249:苏丹',
            'SR' => 'SR:00597:苏里南',
            'SZ' => 'SZ:00268:斯威士兰',
            'SE' => 'SE:0046:瑞典',
            'CH' => 'CH:0041:瑞士',
            'SY' => 'SY:00963:叙利亚',
            'TJ' => 'TJ:00992:塔吉克斯坦',
            'TZ' =>	'TZ:00255:坦桑尼亚',
            'TW' => 'TW:00886:台湾 （中国）',
            'TH' => 'TH:0066:泰国',
            'TT' => 'TT:001868:特立尼达和多巴哥',
            'TL' => 'TL:00670:东帝汶',
            'TG' => 'TG:00228:多哥',
            'TK' => 'TK:00690:托克劳',
            'TO' => 'TO:00676:汤加',
            'TN' => 'TN:00216:突尼斯',
            'TR' => 'TR:0090:土耳其',
            'TM' => 'TM:00993:土库曼斯坦',
            'TV' => 'TV:00688:图瓦卢',
            'UG' => 'UG:00256:乌干达',
            'UA' => 'UA:00380:乌克兰',
            'AE' => 'AE:00971:阿拉伯联合酋长国',
            'UK' => 'UK:0044:英国',
            'US' => 'US:001:美国',
            'UY' => 'UY:00598:乌拉圭',
            'UZ' => 'UZ:00998:乌兹别克斯坦',
            'VU' => 'VU:00678:瓦努阿图',
            'VA' => 'VA:00379:梵蒂冈',
            'VE' => 'VE:0058:委内瑞拉',
            'VN' => 'VN:0084:越南',
            'WF' => 'WF:00681:瓦利斯群岛和富图纳群岛',
            'EH' => 'EH:00210:西撒哈拉',
            'YE' => 'YE:00967:也门',
            'ZM' => 'ZM:00260:赞比亚',
            'ZW' => 'ZW:00263:津巴布韦',
        	'GL' => 'GL:00299:格陵兰',
        	'VI' => 'VI:001340:维尔京群岛(美国)'
		);
		$p = trim(strtoupper($p));
        $field = trim(strtoupper($field));

        if ($p === 'ALL') {
            foreach ($country as $k => $v) {
                list($iso, $en, $cn) = explode(':', $v);
                $country[$k] = array('ISO' => $iso, 'CODE' => $en, 'CN' => $cn);
            }
            if ($field !== 'ALL') {
                foreach ($country as $k => $v) {
                    $country[$k] = $v[$field];
                }
            }
            return $country;
        }
        if (isset($country[$p])) {
            $p = $p === 'GB' ? 'UK' : $p;
            $c = explode(':', $country[$p]);
            $r = array('ISO' => $c[0], 'CODE' => $c[1], 'CN' => $c[2]);
            return ($field === 'ALL') ? $r : $r[$field];
        }
        return "未知";
	}
	
	

}